<?php

/**
 * Chart Web Service class
 *
 * Provides Chart Web Wervice functions
 *
 * @name TransferStatistics
 * @author DiMoN
 * @copyright Dmitry Pavlov
 */

class TransferChart
{
    /**
     * Plot chart of the certain type according to the parameters
     *
     * @param string $xml - XML with the chart data
     * @param string $type - Chart type
     * @return string - response XML with the function result
     */
    public function plotChart($xml, $type)
    {
        try
        {
            include 'core/Dispatcher.php';
            include 'core/XMLChart.php';
            include 'core/classes.php';
            include 'core/Charts/Chart.php';
            include 'lib/Service.php';
            include 'lib/Settings.php';

            $XMLChart = new XMLChart($xml);

            $chart = new Chart($XMLChart->DataArray2D, $XMLChart->DataArray3D,
            $XMLChart->LabelsArray, $XMLChart->LegendArray,
            $XMLChart->Title, $XMLChart->ParameterName, $XMLChart->NameX, $XMLChart->NameY);

            $dispatcher = new Dispatcher();
            $specifiedChart = $dispatcher->getChart($type);
            $path = Settings::serviceHTTPPath() . $specifiedChart->plot();

            $response = Service::formResponseXML($path, 0);
        }
        catch (Exception $e)
        {
            $response = Service::formResponseXML($e->getMessage(), $e->getCode());
        }

        $resultText = $response;
        return $resultText;
    }

    /**
     * Get list of available charts
     *
     * @return string - response XML with the function result
     */
    public function getListCharts()
    {
        try
        {
            include 'core/Dispatcher.php';
            include 'core/XMLChart.php';
            include 'core/classes.php';
            include 'core/Charts/Chart.php';
            include 'lib/Service.php';
            include 'lib/Settings.php';

            $dispatcher = new Dispatcher();
            $response = Service::formResponseXML($dispatcher->getXMLListCharts(), 0);
        }
        catch (Exception $e)
        {
            $response = Service::formResponseXML($e->getMessage(), $e->getCode());
        }

        $resultText = $response;
        return $resultText;
    }
}

$server = new SoapServer("TransferChart.wsdl");
$server->setClass("TransferChart");
$server->handle();
?>